package com.ruoyi.APPMS.service.impl;

import com.ruoyi.APPMS.domain.Chart;
import com.ruoyi.APPMS.mapper.ChartMapper;
import com.ruoyi.APPMS.service.IChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ChartServiceImpl implements IChartService {
    @Autowired
    ChartMapper chartMapper;

    @Override
    public List<Chart> listchart() {
        Long vehicle = chartMapper.getvehiclecount();
        Long part = chartMapper.getpartcount();
        Double dvehicle = Double.valueOf(vehicle);
        Double dpart = (double) (part / 5);
        Double empty = 100 - dvehicle - dpart;
        List<Chart> chartList = new ArrayList<>();
        Chart chart1 = new Chart();
        chart1.setValue(dvehicle);
        chart1.setName("车辆");
        chartList.add(chart1);
        Chart chart2 = new Chart();
        chart2.setValue(dpart);
        chart2.setName("零部件");
        chartList.add(chart2);
        Chart chart3 = new Chart();
        chart3.setValue(empty);
        chart3.setName("空闲");
        chartList.add(chart3);
        return chartList;
    }

    @Override
    public Long customercount() {
        return chartMapper.getcustomercount();
    }

    @Override
    public Long salespersoncount() {
        return chartMapper.getsalespersoncount();
    }

    @Override
    public Long vehiclesaledcount() {
        return chartMapper.getvehiclesaledcount();
    }

    @Override
    public Long partsaledcount() {
        return chartMapper.getpartsaledcount();
    }

    @Override
    public List<Chart> brandsalecount() {
        List<String> name = chartMapper.getbrandsalename();
        List<Long> number = chartMapper.getbrandsalenumber();
        List<Chart> chartList = new ArrayList<>();
        for (int i = 0; i < name.size(); i++) {
            Chart chart = new Chart();
            chart.setValue(Double.valueOf(number.get(i)));
            chart.setName(name.get(i));
            chartList.add(chart);
        }
        return chartList;
    }

    @Override
    public List<Chart> colorsalecount() {
        List<String> name = chartMapper.getcolorsalename();
        List<Long> number = chartMapper.getcolorsalenumber();
        List<Chart> chartList = new ArrayList<>();
        for (int i = 0; i < name.size(); i++) {
            Chart chart = new Chart();
            chart.setValue(Double.valueOf(number.get(i)));
            chart.setName(name.get(i));
            chartList.add(chart);
        }
        return chartList;
    }

    @Override
    public List<Chart> partsalecount() {
        List<String> name = chartMapper.getpartname();
        List<Long> number = chartMapper.getpartnumber();
        List<Chart> chartList = new ArrayList<>();
        for (int i = 0; i < name.size(); i++) {
            Chart chart = new Chart();
            chart.setValue(Double.valueOf(number.get(i)));
            chart.setName(name.get(i));
            chartList.add(chart);
        }
        return chartList;
    }

    @Override
    public List<List<?>> salepersonachivement() {

        List<String> saleman = chartMapper.getsalepersonname();           // 销售员列表
        List<Long> profit = chartMapper.getsalepersonachivement();
        List<List<?>> form = new ArrayList<>();
        form.add(saleman);
        form.add(profit);
        return form;
    }

    @Override
    public List<List<?>> showvehicleprofit() {
        List<String> month = chartMapper.getMonth();                        // 获取销售员名称
        List<Long> vehicleprofit = chartMapper.getvehicleprofit();          // 获取业绩
        List<List<?>> form = new ArrayList<>();
        form.add(month);
        form.add(vehicleprofit);
        return form;
    }
    @Override
    public List<List<?>> showpartprofit() {
        List<String> month = chartMapper.getMonth();                        // 获取销售员名称
//        List<Long> vehicleprofit = chartMapper.getvehicleprofit();          // 获取业绩
        List<Long> pathprofit = chartMapper.getpartprofit();          // 获取业绩
        List<List<?>> form = new ArrayList<>();
        form.add(month);
//        form.add(vehicleprofit);
        form.add(pathprofit);
        return form;
    }

}
